exports.GiftMainView = UI.View.subclass(
{
    className: "GiftMainView",
    initialize: function($super) 
    {
    	$super();
        this.setFrame([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(320),TCUtil.getAdjustedY(480)])
        //this.setBackgroundColor("000077BC");
      	
    },
    
    createView: function()
    {
   		this.addBackground();
        this.addCloseBtn();
        this.addTopLabel();

		this.addStoreAndDecorationButtons();

		this.storeButtonAction(); 
		this.checkAndShowTutorialIndicator();
    },
   
   	addStoreAndDecorationButtons: function ()
   	{
   		if(TutorialManager.getHasCompletedTutorial())
   		{
	   		var buttonNormal = this.getBaseResourcePath()+"button-normal.png";
	   		var buttonPressed = this.getBaseResourcePath()+"button-pressed.png";
	   		this._storeButton = UIFactory.getGenericButton([TCUtil.getAdjustedX(80),TCUtil.getAdjustedY(380),TCUtil.getAdjustedX(70),TCUtil.getAdjustedY(40)], buttonNormal, buttonPressed, Core.Localization.getString("STORES"), null, TCUtil.getAdjustedFontSize(70), this,null);
	        this.addChild(this._storeButton);
	        this._storeButton.onclick = function() 
		        {
		            this.storeButtonAction();
		        }.bind(this);
	        
	        this._decorationButton = UIFactory.getGenericButton([TCUtil.getAdjustedX(170),TCUtil.getAdjustedY(380),TCUtil.getAdjustedX(70),TCUtil.getAdjustedY(40)], buttonNormal, buttonPressed, Core.Localization.getString("DECORATIONS"), null, TCUtil.getAdjustedFontSize(70), this,null);
	        this.addChild(this._decorationButton);
	        this._decorationButton.onclick = function() 
		        {
		            this.decorationButtonAction();
		        }.bind(this);
   		}
   	},
   	
   	checkAndShowTutorialIndicator: function()
   	{
		if(!TutorialManager.getHasCompletedTutorial())
		{
			this.swingAnimation = new SwingAnimation(kSwingDirection.kSwingDirectionRight);
			this.swingAnimation.setPosition([TCUtil.getAdjustedX(5),TCUtil.getAdjustedY(140)]);
			this.swingAnimation.createView();
			this.addChild(this.swingAnimation);
		}
   	},
   	
   	storeButtonAction: function()
   	{
   		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
   		if(TutorialManager.getHasCompletedTutorial())
   		{
	   		var buttonDisabled = this.getBaseResourcePath()+"button-disabled.png";
	   		this._decorationButton.setState(UI.State.Normal);
	   		this._storeButton.setImage(buttonDisabled, UI.State.Disabled);
	   		this._storeButton.setState(UI.State.Disabled);
	   		this._topLabel.setText(Core.Localization.getString("STORES"));
   		}
		if(this._tableView)
		{
			this._tableView.destroy();
			this._tableView = null;
		}
		var type = kGiftType.kGiftTypeStore;
		this._tableView = new GiftGenericTableView(this,type);     
   		this.addChild(this._tableView);
   	},
   	   	
   	decorationButtonAction: function()
   	{
   		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
   		var buttonDisabled = this.getBaseResourcePath()+"button-disabled.png";
   		this._storeButton.setState(UI.State.Normal);
   		this._decorationButton.setImage(buttonDisabled, UI.State.Disabled);
   		this._decorationButton.setState(UI.State.Disabled);
   		this._topLabel.setText(Core.Localization.getString("DECORATION"));

		if(this._tableView)
		{
			this._tableView.destroy();
			this._tableView = null;
		}
		var type = kGiftType.kGiftTypeDecoration;
		this._tableView = new GiftGenericTableView(this,type);     
   		this.addChild(this._tableView);
   	},
   	
    addBackground: function()
    {
    	var backgroundImagePath = this.getBaseResourcePath() + "background.png";
		this._backgroundImage =  UIFactory.getImage([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(45),TCUtil.getAdjustedX(320),TCUtil.getAdjustedY(380)], backgroundImagePath); 
        this.addChild(this._backgroundImage);
    },
    
   addCloseBtn: function()
    {
    	if(TutorialManager.getHasCompletedTutorial())
    	{
	    	var closeButtonNormalImagePath = this.getBaseResourcePath() + "close-button-normal.png";
	    	var closeButtonSelectedImagePath = this.getBaseResourcePath() + "close-button-pressed.png";
	    	
	    	this._closeBtn = UIFactory.getGenericButton([TCUtil.getAdjustedX(260), TCUtil.getAdjustedY(50), TCUtil.getAdjustedY(40), TCUtil.getAdjustedX(40)], closeButtonNormalImagePath,closeButtonSelectedImagePath,null,null,null, this);	
			this.addChild(this._closeBtn);
			
			this._closeBtn.onclick = function()
	    	{
	    		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
				this.removeFromParent();
				this.destroy();
	   		}.bind(this);
    	}
    },
    
    addTopLabel: function()
    {
    	this._topLabel = UIFactory.getTextArea([TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(55), TCUtil.getAdjustedX(120), TCUtil.getAdjustedY(45)], Core.Localization.getString("GIFTS"), TCUtil.getAdjustedFontSize(70), UI.ViewGeometry.Gravity.Center);
	   	this.addChild(this._topLabel);
    },
    	
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/gifttableview/";
	},

    destroy: function()
    {
    	if(this._tableView)
    	{
			this._tableView.destroy();
    		this._tableView = null;
    	}
    	if(this._backgroundImage)
    	{
    		this._backgroundImage.destroy();
    		this._backgroundImage = null;
    	}
    	if(this._closeBtn)
    	{
    		this._closeBtn.destroy();
    		this._closeBtn = null;
    	}
    	if(this._topLabel)
    	{
    		this._topLabel.destroy();
    		this._topLabel = null;
    	}
    	if(this._decorationButton)
    	{
    		this._decorationButton.destroy();
    		this._decorationButton = null;
    	}
    	if(this._storeButton)
    	{
    		this._storeButton.destroy();
    		this._storeButton = null;
    	}
    	if(this.swingAnimation)
    	{
    		this.swingAnimation.destroy();
    		this.swingAnimation = null;
    	}
    },
});
